home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Celestin Apprentice 5
/
Apprentice-Release5.iso
/
Source Code
/
C
/
Frameworks
/
Grant's CGI Framework 1.0b14
/
Util
/
StringUtil.c
< prev
next >
Wrap
Text File
|
1996-04-11
|
4KB
|
168 lines
/*****
*
* StringUtil.c
*
* This is a support file for "Grant's CGI Framework".
* Please see the license agreement that accompanies the distribution package
* for licensing details.
*
* Copyright ©1995,1996 by Grant Neufeld
* grant@acm.com
* http://arpp.carleton.ca/grant/
*
*****/
#include <string.h>
#include "compiler_stuff.h"
#include "StringUtil.h"
/*** FUNCTIONS ***/
/* Copy pascal format srcStr to the destStr */
void
StringPascalCopy ( char *srcStr, char *destStr )
{
BlockMove ( srcStr, destStr, (srcStr[nil]) + 1 );
} /* StringPascalCopy */
/* count the occurances of theChar in theString */
long
StringCountChar ( char *theString, char theChar )
{
long total;
char * tempStr;
total = nil;
tempStr = theString;
do
{
/* get a ptr to the next instance of theChar */
tempStr = StringChar ( tempStr, theChar );
if ( (tempStr != NULL) && (*tempStr != nil) )
{
tempStr++;
total++;
}
} while ( (tempStr != NULL) && (*tempStr != nil) );
return total;
} /* StringCountChar */
/* Returns true if any chars were converted */
Boolean
StringConvertCharToChar ( char *ioString, char fromChar, char toChar )
{
Boolean didConvert;
didConvert = false;
while ( ioString[0] != nil )
{
if ( ioString[0] == fromChar )
{
ioString[0] = toChar;
didConvert = true;
}
ioString++;
}
return didConvert;
} /* StringConvertCharToChar */
/* working version of strchr for TPM */
#if kCompiling_For_Symantec
char *
StringChar ( const char *theString, unsigned char theChar )
{
do
{
if ( *theString == theChar )
{
/* found the character, return a pointer to it */
return (char *)theString;
}
theString++;
} while ( *theString != nil );
/* didn't find the character */
return NULL;
} /* StringChar */
#endif
/** TEXT DRAWING FUNCTIONS **/
/* Font, size, style, etc. must be set before this function is called. */
void
StringDrawInRect ( StringPtr theString, Rect theRect )
{
if ( theString[nil] > nil )
{
StringDrawTextInRect ( (char *)(theString + 1), theString[nil], theRect );
}
} /* StringDrawInRect */
/* returns the number of characters not drawn because of insufficient space.
zero if every character drawn */
long
StringDrawTextInRect ( char *theText, long totalLength, Rect theRect )
{
char * currentStartOfText;
long charsLeftInText;
long currentNumCharsToPrint;
FontInfo fInfo;
short textLineHeight;
short currentVPosition;
short hPosition;
StyledLineBreakCode theBreakCode;
Fixed rectWidth;
Fixed textWidth;
/* initialize text values */
currentStartOfText = theText;
charsLeftInText = totalLength;
currentNumCharsToPrint = charsLeftInText;
GetFontInfo ( &fInfo );
/* initialize spacing */
textLineHeight = fInfo.ascent + fInfo.descent + fInfo.leading;
currentVPosition = theRect.top + fInfo.ascent;
hPosition = theRect.left;
rectWidth = Long2Fix ( theRect.right - theRect.left );
/* clear the rectangle where the text is to be displayed */
EraseRect ( &theRect );
/* while there are still characters in the text that haven't been drawn
and there is still room in the Rect for drawing more characters */
while ( (charsLeftInText > nil) && (currentVPosition < theRect.bottom) )
{
textWidth = rectWidth;
theBreakCode = StyledLineBreak ( currentStartOfText, charsLeftInText, nil,
charsLeftInText, nil, &textWidth, ¤tNumCharsToPrint);
MoveTo ( hPosition, currentVPosition );
DrawText ( currentStartOfText, nil, currentNumCharsToPrint );
currentVPosition += textLineHeight;
charsLeftInText -= currentNumCharsToPrint;
currentStartOfText += currentNumCharsToPrint;
} /* end of while */
return charsLeftInText;
} /* StringDrawTextInRect */
/*** EOF ***/